<?php slot('menu_sidebar') ?>
    <?php include_partial('opciones',array('alumno' => $alumno)); ?>
 <?php end_slot(); ?>

<?php


 foreach ($cursos as $curso):


// echo $curso->getDia ();
// echo $curso->getHora_desde ();
// echo $curso->getHora_hasta ();


$Horario[0][0]=$curso->getNombre ();

$obj_curso = Doctrine_Core::getTable('curso')->find($curso->getid_curso());
$horas = $obj_curso -> getHorarios();

foreach ($horas as $hora):

if ($hora -> getHora_desde() != ""){


    $next_time = $hora -> getHora_desde();
$i=0;
    while ($next_time < $hora -> getHora_hasta()){
$i++;

//echo $curso->getId_curso (). " ";
//echo $curso->getNombre (). " ";
//echo $hora -> getDia() . " ";
//echo $hora -> getHora_desde() . " ";
//echo $hora -> getHora_hasta() ." ";

//echo date($hora -> getHora_desde()+ "00:15") . " ";



$event_time = $next_time;
$event_length = 15;
$timestamp = strtotime("$event_time");
$etime = strtotime("+$event_length minutes", $timestamp);

//echo $next_time;
//echo "<br/>";



$next_time = date('H:i:s', $etime);




}

if ( $hora -> getDia()== 1) {

    $n = ((int) (substr($hora -> getHora_desde(),0,2)) - 6) * 4 + (int) (substr($hora -> getHora_desde(),3,2)) / 15;
  //  echo "Lunes " .  $curso->getNombre (). " " . $hora -> getHora_desde() . " " . $i . " " . substr($hora -> getHora_desde(),0,2) . " " . substr($hora -> getHora_desde(),3,2) . " " . $n . " <br/>";

$lunes[$n][0] = $curso->getNombre ();
$lunes[$n][2] = $hora -> getHora_desde();
$lunes[$n][1] = $i;
$lunes[$n][2] = ($curso -> getId_curso())% 10;
for ($hh=1;$hh<$i;$hh++) {
$lunes[$n+$hh][0] = "FLAG ROWSPAN";
}
$hh=0;



}

if ( $hora -> getDia()== 2) {

    $n = ((int) (substr($hora -> getHora_desde(),0,2)) - 6) * 4 + (int) (substr($hora -> getHora_desde(),3,2)) / 15;
   // echo "martes " .  $curso->getNombre (). " " . $hora -> getHora_desde() . " " . $i . " " . substr($hora -> getHora_desde(),0,2) . " " . substr($hora -> getHora_desde(),3,2) . " " . $n . " <br/>";

$martes[$n][0] = $curso->getNombre ();
$martes[$n][2] = $hora -> getHora_desde();
$martes[$n][1] = $i;
$martes[$n][2] = ($curso -> getId_curso())% 10;
//for ($hh=1;$hh<$i;$hh++) {
//$lunes[$n+$hh][0] = "FLAG ROWSPAN";
//}
for ($hh=1;$hh<$i;$hh++) {
$martes[$n+$hh][0] = "FLAG ROWSPAN";
}
//$hh=0;



}
if ( $hora -> getDia()== 3) {

    $n = ((int) (substr($hora -> getHora_desde(),0,2)) - 6) * 4 + (int) (substr($hora -> getHora_desde(),3,2)) / 15;
  //  echo "miercoles " .  $curso->getNombre (). " " . $hora -> getHora_desde() . " " . $i . " " . substr($hora -> getHora_desde(),0,2) . " " . substr($hora -> getHora_desde(),3,2) . " " . $n . " <br/>";

$miercoles[$n][0] = $curso->getNombre ();
$miercoles[$n][1] = $hora -> getHora_desde();
$miercoles[$n][1] = $i;
$miercoles[$n][2] = ($curso -> getId_curso())% 10;
for ($j=1;$j<$i;$j++) {
$miercoles[$n+$j][0] = "FLAG ROWSPAN";
}


}
if ( $hora -> getDia()== 4) {

    $n = ((int) (substr($hora -> getHora_desde(),0,2)) - 6) * 4 + (int) (substr($hora -> getHora_desde(),3,2)) / 15;
 //   echo "jueves " .  $curso->getNombre (). " " . $hora -> getHora_desde() . " " . $i . " " . substr($hora -> getHora_desde(),0,2) . " " . substr($hora -> getHora_desde(),3,2) . " " . $n . " <br/>";

$jueves[$n][0] = $curso->getNombre ();
$jueves[$n][1] = $hora -> getHora_desde();
$jueves[$n][1] = $i;
$jueves[$n][2] = ($curso -> getId_curso())% 10;
for ($j=1;$j<$i;$j++) {
$jueves[$n+$j][0] = "FLAG ROWSPAN";
}


}

if ( $hora -> getDia()== 5) {

    $n = ((int) (substr($hora -> getHora_desde(),0,2)) - 6) * 4 + (int) (substr($hora -> getHora_desde(),3,2)) / 15;
  //  echo "viernes " .  $curso->getNombre (). " " . $hora -> getHora_desde() . " " . $i . " " . substr($hora -> getHora_desde(),0,2) . " " . substr($hora -> getHora_desde(),3,2) . " " . $n . " <br/>";

$viernes[$n][0] = $curso->getNombre ();
$viernes[$n][1] = $hora -> getHora_desde();
$viernes[$n][1] = $i;
$viernes[$n][2] = ($curso -> getId_curso())% 10;
for ($j=1;$j<$i;$j++) {
$viernes[$n+$j][0] = "FLAG ROWSPAN";
}


}


}



 endforeach;


 endforeach;

//echo "<br/>";
//echo "<br/>";
echo "<br/>";

//echo "------------------------<br/>";
//echo " LUNES";
//for ($i=0; $i < 67; $i++ ){
  //  if ($lunes [$i][0] != ""){
    //    echo $i;
      //  echo " ";
    //    echo $lunes [$i][0];
  //      echo " ";
//        echo $lunes [$i][1];
    //    echo " ";
  //      echo $lunes [$i][2];
//        echo " ";

    //    echo "<br/>";
  //  }
//}





///////////////////////////
array (color);
$color[0]="#99FF33";
$color[1]="#FFCC00";
$color[2]="#99CCCC";
$color[3]="#CC99CC";
$color[4]="#669900";
$color[5]="#FF9966";
$color[6]="#66FFCC";
$color[7]="#00CCFF";
$color[8]="#9966FF";
$color[9]="#CC9933";



?>

<table  border="1" cellspacing="0" bordercolor="#000000" >

    <tr>
   <td  align="center" bordercolor="#000000" bgcolor="#FFFF99" width="50"  height="10"></td>

   <td  align="center" bordercolor="#000000" bgcolor="#FFFF99" width="150" height="10">LUNES</td>

   <td  align="center" bordercolor="#000000" bgcolor="#FFFF99" width="150"  height="10">MARTES</td>
<td  align="center" bordercolor="#000000" bgcolor="#FFFF99" width="150"  height="10">MIERCOLES</td>
<td  align="center" bordercolor="#000000" bgcolor="#FFFF99" width="150"  height="10">JUEVES</td>
<td  align="center" bordercolor="#000000" bgcolor="#FFFF99" width="150"  height="10">VIERNES</td>


    </tr>




<?php

$i=0;
for ($j=0;$j<36;$j++) {



?>

    <tr>

<?php

if ($j%4 == 0){
?>

    <td  align="center" bordercolor="#000000" bgcolor="<?php if ($i%2 ==0){echo "#FFFF66";} else{ echo "#FFFF99";}; ;?>" width="50" rowspan="4" height="10"><?php echo ($i + 6);?></td>
<?php
$i++ ;
}



if ($lunes[$j][0] != "" and $lunes[$j][0] != "FLAG ROWSPAN" ){
?>
    <td  span class="EstiloHorario" align="center"  bgcolor="<?php echo $color[(int) ($lunes[$j][2])]; ?>" bordercolor="#000000" width="150" rowspan="<?php echo $lunes[$j][1] ?>"><?php echo $lunes[$j][0] ?></td>
<?php
}


if ($lunes[$j][0] == "" ){
?>
    <td width="150" bgcolor="<?php if ($j%2 ==0){echo "#FFFF66";} else{ echo "#FFFF99";}; ;?>" ></td>
<?php
}




//martes

if ($martes[$j][0] != "" and $martes[$j][0] != "FLAG ROWSPAN" ){
?>
    <td  span class="EstiloHorario" align="center"  bgcolor="<?php echo $color[$martes[$j][2]]; ?>" bordercolor="#000000" width="150" rowspan="<?php echo $martes[$j][1] ?>"><?php echo $martes[$j][0] ?></td>
<?php
}


if ($martes[$j][0] == "" ){
?>
    <td width="150" bgcolor="<?php if ($j%2 ==0){echo "#FFFF66";} else{ echo "#FFFF99";}; ;?>" ></td>
<?php
}





//MIERCOLES

if ($miercoles[$j][0] != "" and $miercoles[$j][0] != "FLAG ROWSPAN" ){
?>
    <td  span class="EstiloHorario" align="center"  bgcolor="<?php echo $color[$miercoles[$j][2]]; ?>" bordercolor="#000000" width="150" rowspan="<?php echo $miercoles[$j][1] ?>"><?php echo $miercoles[$j][0] ?></td>
<?php
}


if ($miercoles[$j][0] == "" ){
?>
    <td width="150" bgcolor="<?php if ($j%2 ==0){echo "#FFFF66";} else{ echo "#FFFF99";}; ;?>" ></td>
<?php
}

if ($jueves[$j][0] != "" and $jueves[$j][0] != "FLAG ROWSPAN" ){
?>
    <td  span class="EstiloHorario" align="center"  bgcolor="<?php echo $color[$jueves[$j][2]]; ?>" bordercolor="#000000" width="150" rowspan="<?php echo $jueves[$j][1] ?>"><?php echo $jueves[$j][0] ?></td>
<?php
}


if ($jueves[$j][0] == "" ){
?>
    <td width="150" bgcolor="<?php if ($j%2 ==0){echo "#FFFF66";} else{ echo "#FFFF99";}; ;?>" ></td>
<?php
}


//viernes

if ($viernes[$j][0] != "" and $viernes[$j][0] != "FLAG ROWSPAN" ){
?>
    <td  span class="EstiloHorario" align="center" bgcolor="<?php echo $color[$viernes[$j][2]]; ?>" bordercolor="#000000" width="150" rowspan="<?php echo $viernes[$j][1] ?>"><?php echo $viernes[$j][0] ?></td>
<?php
}


if ($viernes[$j][0] == "" ){
?>
    <td width="150" bgcolor="<?php if ($j%2 ==0){echo "#FFFF66";} else{ echo "#FFFF99";}; ;?>" ></td>
<?php
}

?>


 <td width="0" height="10" bgcolor="<?php if ($j%2 ==0){echo "#FFFF66";} else{ echo "#FFFF99";}; ;?>" ></td>

    </tr>
<?php

}

?>

</table>